const { defineStore } = Pinia;

export const useCounterStore = defineStore('counter', {
    state: () => ({
        count: 0,
    }),
    getters: {
        doubleCount: (state) => state.count * 2,
    },
    actions: {
        increment() {
            this.count++;
        },
        decrement() {
            this.count--;
        },

    },
    // 启用持久化
    persist: {
        // 持久化存储的路径
        key: 'custom-key', // 默认是 store 的 id

        // 存储到 sessionStorage 而不是 localStorage
        // storage: sessionStorage,

        // 指定要持久化的部分状态
        paths: ['count'], // 只有 count 会被持久化
    }
});